﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Boggle;

namespace BoggleGUI
{
    public delegate void SaveEventHandler(object sender, ArrayEventArgs e);
    
    /// <summary>
    /// Interaction logic for SettingsWindow.xaml
    /// </summary>
    public partial class SettingsWindow : Window
    {
        public event SaveEventHandler SaveEvent;
        
        public SettingsWindow(string name, string server)
        {
            InitializeComponent();
            nameTextBox.Text = name;
            serverTextBox.Text = server;

            Keyboard.Focus(nameTextBox);
            nameTextBox.Select(0, nameTextBox.Text.Length);
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            //this.Hide();
            //e.Cancel = true;
        }

        private void cancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            if (nameTextBox.Text != "" & serverTextBox.Text != "")
            {

                string[] settings = new string[2];

                settings[0] = nameTextBox.Text;
                settings[1] = serverTextBox.Text;

                if (SaveEvent != null)
                {
                    SaveEvent(this, new ArrayEventArgs(settings));
                }

                this.Close();
            }
        }
    }
}
